package com.zsummer.zero.thread;

/**
 * ThreadLocal��ʹ��
 * @author zhouyujiang
 *
 */
public class ThreadDemo9 {
	private static final ThreadLocal<String> stringLocal = new ThreadLocal<String>();
	private static final ThreadLocal<Teacher> teacherLocal = new ThreadLocal<Teacher>() {
		protected Teacher initialValue() {
			return new Teacher("����", "17");
		};
	};
	
	public static String get() {
		return stringLocal.get();
	}
	
	public static void set(String str) {
		stringLocal.set(str);
	}
	
	public static void main(String[] args) {
		ThreadDemo9.set("zhang");
		System.out.println(ThreadDemo9.get());
		System.out.println(teacherLocal.get().name);
		Thread thread = new Thread(new Runnable() {
			
			@Override
			public void run() {
				ThreadDemo9.set("li");
				System.out.println(ThreadDemo9.get());
				System.out.println(teacherLocal.get().name = "С��");
				System.out.println(teacherLocal.get().name);
			}
		});
		thread.start();
		try {
			thread.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(ThreadDemo9.get());
		System.out.println(teacherLocal.get().name);
	}
}

class Teacher {
	String name;
	String age;
	public Teacher(String name, String age) {
		this.name = name;
		this.age = age;
	}
}
